Open
Conversation
Member
|
What do you think of this? In the first example, we tell CalculatesRoute.calculate to not only have a message expectation, but to also return the data structure that is expected of it. (note that this is usually a code smell that your code is doing too much in one method). In thee second example, we stub into calculate and tell it to return the results we want, and assert later that it's present. it "should calculate a route via the CalculatesRoute" do
start = stub(name: "Atlanta, GA")
last = stub(name: "Marietta, GA")
cities = [start, last]
subject.stub(:cities) { cities }
CalculatesRoute
.should_receive(:calculate)
.with(cities, start)
.and_return( {route: stub, distance: 100} )
subject.route("Atlanta, GA")
end
it "should return the route from CalculatesRoute" do
route_stub = [stub("Marietta, GA"), stub("Atlanta, GA")]
start = stub("Marietta, GA")
CalculatesRoute.stub(:calculate){ {route: route_stub, distance: 100} }
subject.route("Atlanta, GA").fetch(:route).should eq(route_stub)
endThoughts? If you can take this and re-submit (or turn it into your own words), I can comb over the full result and give more hints. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I cold really use some help with the sales_person_spec.rb tests. I had a really hard time changing the tests to work with the starting city and total distance that I wanted to pass or return. Right now two of the tests are failing because of the fetch I'm doing in route, but I'm not sure how to make dummy information available for results of calculate.